package com.appointmentmanager.web;

//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.appointmentmanager.model.User;
import com.appointmentmanager.service.UserService;

/**
 * Handles requests for the application home page.
 */
@Controller
public class HomeController {
	
//	private Logger logger = LoggerFactory.getLogger(getClass());
	
	private UserService userService;
	
	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	
	/**
	 * Simply selects the home view to render by returning its name.
	 */
	@RequestMapping(value = "/", method = RequestMethod.GET)
	public String home(Model model) {
//		logger.info("Welcome home!");
		
		User currentUser = this.userService.getCurrentUser();
		if (this.userService.isAdmin(currentUser.getUsername())) {
			return "redirect:/admin/announcement";
		}
		
		return "redirect:/announcement";
	}
	
}
